<?php
class ml_model_dbCollectionRe extends Lib_datamodel_db
{

    public function __construct()
    {
        $db_config = ml_factory::load_standard_conf('db');
        parent::__construct('collection_re' , $db_config['collection_re']);
    }

    public function getListByCid($uid,$cid,$begin=0,$count=40){
        if(!$this->init_db($uid, self::DB_SLAVE))
        return false;
        $uid=$this->escape($uid);
        $cid=$this->escape($cid);
        $sql="select `id`,`rid`,`comment`,`uid`,`ctime`,`col_id` from `$this->table` where `col_id`='$cid' and `status`='1' order by `ctime` desc limit $begin,$count";
        $rs=$this->fetch($sql);
        
        return $rs?$this->_data:false;
    }

    public function getTotalByCid($uid,$cid){
        if(!$this->init_db($uid, self::DB_SLAVE))
        return false;
        $uid=$this->escape($uid);
        $cid=$this->escape($cid);
        $sql="select count(*) as `num` from `$this->table` where `col_id`='$cid' and `status`='1'";
        $rs=$this->fetch($sql);
        return $rs?$this->_data[0]:false;
    }
    /**
     *
     * 查看是否收藏了
     * xinhua
     *
     *
     */
    public function verifyCollected($uid,$cid,$rid){
        if(!$this->init_db($uid, self::DB_SLAVE))
        return false;
        $sql="select * from `$this->table` where `col_id`='$cid' and `rid`='$rid' and  `status`='1'";

        $rs=$this->fetch($sql);
        
        return $rs?$this->_data:false;
            
    }
    public function submitRepost($uid,$cid,$rid,$comment){

        if(!$this->init_db($uid, self::DB_MASTER))
        return false;

        $arrInsert = array(
            'rid' => $rid,
            'col_id' => $cid,
            'ctime' => date('Y-m-d H:i:s', time()),
            'status' => '1',
            'cip' => Tool_ip::get_real_ip(),
            'comment'=>$comment,
            'uid'=>$uid

        );

        return $this->insert($arrInsert);

    }
    /**
     *
     * 删除专辑内容时，获得下个缩略图的pid
     * xinhua
     *
     *
     */
    public function get_next_pid($uid,$cid){
        if(!$this->init_db($uid, self::DB_SLAVE))
        return false;
        $sql="select `rid` from `$this->table` where `col_id`='$cid' and `status`='1' order by `ctime` desc limit 9,1";

        $rs=$this->fetch($sql);

        return $rs?$this->_data[0]:false;
            
    }
    /**
     *
     * 删除专辑内容时，修改status=9
     * xinhua
     *
     *
     */
    public function delContent($uid,$cid,$rid){
        if(!$this->init_db($uid, self::DB_MASTER))
        return false;

        return $this->update(array('status' => '9'), "`col_id`='$cid' and `uid`='$uid' and `rid`='$rid' and `status`='1'", 1);

    }

}

?>